define(['./../initial', './../model/Project', './../controller/project/prjCtrl'], function () {
    var app = angular.module('App');
    app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
        function ($stateProvider, $urlRouterProvider, $locationProvider) {
            $stateProvider
                .state('metro.type', {
                    url: "/type/:type",
                    abstract: true,
                    resolve: {
                        allLines1: ['viewbag', 'allLines', "Project", "typeList", '$stateParams', '$state', function (viewbag, allLines, Project, typeList, $stateParams, $state) {
                            var type = typeList.filter(function (t) {
                                return t.typeCode.toLowerCase() === $stateParams.type.toLowerCase();
                            })[0];
                            if (!type) {
                                $state.go('metro.map');
                                return;
                            }
                            return Project.getAllCityProjects(type.typeCode);
                        }]
                    },
                    views: {

                    }
                })
                .state('metro.type.project', {
                    url: '/project/{id:[0-9]+}',
                    resolve: {
                        curPrj: ['allLines1', 'Project', '$stateParams', '$state', 'viewbag', function (allLines1, Project, $stateParams, $state, viewbag) {
                            //如果已经缓存了该项目,直接返回
                            if (viewbag.curPrj && viewbag.curPrj.prjId === $stateParams.id - 0) return viewbag.curPrj;
                            viewbag.curPrj && (viewbag.curPrj.active = false);
                            var prj = viewbag.curPrj = Project.findPrjById($stateParams.id - 0);
                            if (!prj) {
                                $state.go('metro.map');
                                return;
                            }
                            prj.active = true;
                            return prj;
                        }],
                        monitorPoints: ['curPrj', function (curPrj) {
                            return curPrj.getMonitorPoints();
                        }],
                        statusImageList: ['curPrj', function (curPrj) {
                            curPrj.status && curPrj.status.imagesUrl.map(function (url) {
                                var img = new Image()
                                try {
                                    img.src = url;
                                } catch (error) {
                                    return;
                                }
                            });
                        }]
                    },
                    views: {
                        "content@": {
                            templateUrl: '/partials/metro/project/project',
                            controller: "prjCtrl"
                        }
                    }
                });
        }
    ]);
});